<template>
	<view class="content">
		<z-paging ref="paging" v-model="dataList" @query="queryList">
			<view class="bgRed flex-r ver-c p16" slot="top">
				<!-- <u-search placeholder="搜索商品" :showAction="false" @click="toSearch()" disabled="true"></u-search> -->
				<input
					type="text"
					placeholder="请输入关键字进行搜索"
					v-model="keyword"
					class="f1"
					style="background: #fff; border-radius: 50rpx; font-size: 28rpx; padding: 13rpx; text-align: center"
				/>
				<text @click="searchs()" class="white pl16">搜索</text>
			</view>
			<shopList :list="dataList"></shopList>
		</z-paging>
		<view style="position: fixed; right: 30rpx; bottom: 30rpx; text-align: center; color: #999" @click="toHome">
			<image
				src="https://www.helloimg.com/i/2025/04/08/67f4beceb8efe.png"
				mode="aspectFill"
				style="width: 80rpx; height: 80rpx"
			></image>
		</view>
	</view>
</template>

<script>
import { ImgIP } from '@/utils/comm.js'
import { getGoodList } from '@/api/goods.js'
import { getMerchantInfo } from '@/api/mine.js'
import Utils from '@/utils/utils.js'
import shopList from '@/pages_C/components/shop-list/shop-list.vue'
export default {
	components: {
		shopList
	},
	data() {
		return {
			keyword: '',
			tMerchantid: '',
			dataList: []
		}
	},

	onLoad(option) {
		if (option.q && option.q != 'undefined') {
			// 获取到二维码原始链接内容
			const qrUrl = decodeURIComponent(option.q)
			console.log('原始链接=>', qrUrl)
			let fRandomCode = decodeURI(qrUrl.split('=')[1])
			this.tMerchantid = fRandomCode
			console.log('店铺ID=>：' + fRandomCode)
			this.getMerchantInfo(this.tMerchantid)
		}

		// index 跳转测试
		// this.tMerchantid = option.tMerchantid
		// this.getMerchantInfo(this.tMerchantid)
	},
	methods: {
		getMerchantInfo(tMerchantid) {
			let isLogin = Utils.getToken()
			if (isLogin) {
				getMerchantInfo(tMerchantid).then((res) => {
					uni.setNavigationBarTitle({
						title: res.data.tMerchantname
					})
				})
			} else {
				uni.setNavigationBarTitle({
					title: '****的店'
				})
			}
		},
		searchs() {
			this.$refs.paging.reload()
		},
		queryList(pageNo, pageSize) {
			//组件加载时会自动触发此方法，因此默认页面加载时会自动触发，无需手动调用
			//这里的pageNo和pageSize会自动计算好，直接传给服务器即可

			getGoodList(pageNo, pageSize, this.keyword, this.tMerchantid, '').then(
				(res) => {
					console.log(res)
					this.$refs.paging.complete(res.rows)
				},
				(err) => {
					this.$refs.paging.complete(false)
				}
			)
		},
		getGood() {},
		toHome() {
			uni.switchTab({
				url: '/pages/index/index'
			})
		}
	}
}
</script>

<style scoped lang="stylus">
.content
	min-height 100%
</style>
